package com.steven.im.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.steven.im.R;
import com.steven.im.adapter.IMPhoneListAdapter;
import com.steven.im.base.BaseActivity;
import com.steven.im.entity.IMContacts;
import com.steven.im.utils.TitleBuilder;

import java.util.ArrayList;
import java.util.Collections;

import butterknife.BindView;

public class IMPhoneListActivity extends BaseActivity {
    @BindView(R.id.listview)
    ListView listview;
    @BindView(R.id.title_left)
    ImageView titleLeft;
    @BindView(R.id.title_mid)
    TextView titleMid;
    @BindView(R.id.iv_title_right)
    ImageView ivTitleRight;
    private ArrayList<IMContacts> friends = new ArrayList<>();

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {
        ivTitleRight.setImageResource(R.drawable.icon_search);
        new TitleBuilder(this).setTitleText(getString(R.string.phoneList))
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });
    }

    @Override
    public int intiLayout() {
        return R.layout.activity_im_phonelist;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        loadData();
    }

    private void loadData() {
// 虚拟数据
        friends.add(new IMContacts("李伟"));
        friends.add(new IMContacts("张三"));
        friends.add(new IMContacts("阿三"));
        friends.add(new IMContacts("阿四"));
        friends.add(new IMContacts("段誉"));
        friends.add(new IMContacts("段正淳"));
        friends.add(new IMContacts("张三丰"));
        friends.add(new IMContacts("陈坤"));
        friends.add(new IMContacts("林俊杰1"));
        friends.add(new IMContacts("陈坤2"));
        friends.add(new IMContacts("王二a"));
        friends.add(new IMContacts("林俊杰a"));
        friends.add(new IMContacts("张四"));
        friends.add(new IMContacts("林俊杰"));
        friends.add(new IMContacts("王二"));
        friends.add(new IMContacts("王二b"));
        friends.add(new IMContacts("赵四"));
        friends.add(new IMContacts("杨坤"));
        friends.add(new IMContacts("赵子龙"));
        friends.add(new IMContacts("杨坤1"));
        friends.add(new IMContacts("李伟1"));
        friends.add(new IMContacts("宋江"));
        friends.add(new IMContacts("宋江1"));
        friends.add(new IMContacts("李伟3"));
        //2.对数据进行排序
        Collections.sort(friends);
        //3.设置Adapter
        listview.setAdapter(new IMPhoneListAdapter(this, friends));
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                startActivity(new Intent(IMPhoneListActivity.this, IMUserInfoActivity.class));
            }
        });
    }
}
